/*
 * wavefile.h
 * This file is part of trypsyndsp
 *
 * Copyright (C) 2012 - Luke William Westby
 *
 * trypsyndsp is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * trypsyndsp is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with trypsyndsp. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef WAVEFILE_H
#define WAVEFILE_H

#include <stdint.h>

class WaveFile {
	
	public:
		WaveFile();						// create an empty wave file class
		WaveFile(int fdes);				// open a wave file from a file descriptor
		WaveFile(char *fn);				// open a wave file from a filename
		~WaveFile();					// destructor
		int GetBuffer(float *ubf);		// get data in signed 32-bit float [-1,1]
		int GetBuffer(uint8_t *ub8);	// get data in unsigned 8-bit int
		int GetBuffer(int16_t *ub16);	// get data in signed 16-bit int
		int GetBuffer(int32_t *ub32);	// get data in signed 32-bit int
		int WaveOpen(int fd);				// open a file from a file pointer
		int WaveOpen(char *fn);				// open a file from a filename;
		void WaveClear();					// zero all data and destroy all pointers
		void WavePrint();

	private:
		char description[128];			// identifier for instance
		char *filename;					// filename, if used
		int fd;							// file descriptor, if used
		char ChunkId[5];				// to contain "RIFF\0"
		int ChunkSize;					// size of the file in bytes
		char Format[5];					// to contain "WAVE\0"
		char SubChunk1Id[5];			// to contain "fmt \0"
		int SubChunk1Size;				// size of format header
		int AudioFormat;				// compression code
		int NumChannels;				// number of channels
		int SampleRate;					// samples per second
		int ByteRate;					// bytes per second
		int BlockAlign;					// number of bytes per sample over all channels
		int BitsPerSample;				// bit depth of the audio samples
		char SubChunk2Id[5];			// to contain "data\0"
		int SubChunk2Size;				// size of audio data chunk in bytes
		uint8_t *o_buf;					// original buffer
		uint8_t *u_buf_UI8;				// user buffer, unsigned 8-bit int
		int16_t *u_buf_SI16;			// user buffer, signed 16-bit int
		int32_t *u_buf_SI32;			// user buffer, signed 32-bit int
		float *u_buf_SF32;				// user buffer, signed 32-bit float [-1,1]
};

#endif
